import 'package:csc_picker/csc_picker.dart';
import 'package:flutter/material.dart';
import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/controller/schooladmin.dart';
import 'package:ichinesereader/models/forms/forms.dart';
import 'package:ichinesereader/utils/helper.dart';
import 'package:ichinesereader/widgets/dialogs/changeUserPasswordReactive.dart';
import 'package:reactive_dropdown_search/reactive_dropdown_search.dart';
import 'package:reactive_forms/reactive_forms.dart';
import 'package:reactive_segmented_control/reactive_segmented_control.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/models/school/SchoolAdminProfile.dart';
import 'package:ichinesereader/models/school/SchoolAdminProfileDto.dart';
import 'package:ichinesereader/models/school/SchoolAdminProfileUpdateDto.dart';
import 'package:ichinesereader/models/school/SchoolSettings.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:ichinesereader/pages/schooladmin/adminTeacherEditor.dart';

import '../../themes/appTheme.dart';
import '../../themes/pageStyles.dart';

// ignore: must_be_immutable
class AdminProfileEditor extends StatelessWidget {
  AdminProfileEditor({
    Key? key,
    this.teacherId,
  }) : super(key: key);
  String? teacherId;
  final SchoolAdminController schoolAdminController = Get.find();
  final SchoolAdminProfileFormModel formModel =
      new SchoolAdminProfileFormModel();

  @override
  Widget build(BuildContext context) {
    Log.debug("build AdminProfileEditor");

    String? formCurrentCountry, formCurrentState;
    FormGroup form = formModel.form;
    List<DropdownModel> allProgramTypes = [];
    Constants.nanhaiProgramTypeList.forEach((element) {
      allProgramTypes
          .add(new DropdownModel(element.programName, element.displayName));
    });

    void _onUpdate() {
      Log.debug("form.valid=${form.valid} form.value=${form.value}");

      if (!form.valid) {
        form.markAllAsTouched();
        return;
      }
      var classIdsDropdownModel =
          form.control("school.programs").value as List<DropdownModel>;
      List<String> programTypes = [];
      classIdsDropdownModel.forEach((e) => programTypes.add(e.id.toString()));
      SchoolAdminProfileUpdateDto dto = new SchoolAdminProfileUpdateDto();
      dto.schoolType = form.control('school.type').value;
      dto.district = form.control('school.district').value;
      dto.schoolName = form.control('school.name').value;
      dto.programType = programTypes;
      dto.schoolEmail = form.control('contact.email').value;
      dto.phone = form.control('contact.phone').value;
      dto.address = form.control('address.street').value;
      dto.city = form.control('address.city').value;
      dto.zipCode = form.control('address.zipcode').value;
      dto.timeZone = form.control('school.timezone').value;
      dto.country = formCurrentCountry;
      dto.state = formCurrentState;
      bool disableClassLeaderBoard =
          form.control('leaderboard.disableclass').value;
      bool disableWorldClassLeaderBoard =
          form.control('leaderboard.disableworld').value;
      dto.disableDirectLogin =
          form.control('leaderboard.disableDirectLogin').value;

      schoolAdminController
          .updateSchoolAdminProfile(
              dto, disableClassLeaderBoard, disableWorldClassLeaderBoard)
          .then((statusMessage) {
        if (statusMessage.status == 1000) {
          showSnackMsg('Settings have been updated successfully.');
          // Get.snackbar(
          //     'Message'.tr, 'Settings have been updated successfully.'.tr,
          //     backgroundColor: Theme.of(context).primaryColor,
          //     colorText: Theme.of(context).primaryColorLight,
          //     snackPosition: SnackPosition.BOTTOM);
        } else {
          showSnackMsg('Failed to update settings, please try later!');
          // Get.snackbar(
          //     'Message'.tr, 'Failed to update settings, please try later!'.tr,
          //     backgroundColor: Theme.of(context).primaryColor,
          //     colorText: Theme.of(context).primaryColorLight,
          //     snackPosition: SnackPosition.BOTTOM);
        }
      });
    }

    _buildForm() {
      List<Widget> formWidget = [];

      bool programTypeDropdownModelCompareFn(
          DropdownModel? item, DropdownModel? selectedItem) {
        Log.debug(
            "item=${item.toString()} selectedItem=${selectedItem.toString()}");
        return item != null &&
            selectedItem != null &&
            item.id == selectedItem.id;
      }

      formWidget.add(ReactiveSegmentedControl<String, String>(
        formControlName: 'school.type',
        decoration: InputDecoration(
          labelText: 'School Type'.tr,
          labelStyle: TextStyle(
            fontFamily: 'Montserrat',
            color: Get.isDarkMode ? Get.theme.primaryColorDark : Colors.black,
          ),
          border: OutlineInputBorder(),
          helperText: '',
        ),
        padding: const EdgeInsets.all(0),
        selectedColor: Get.isDarkMode
            ? AppTheme.colors.darkTheme1
            : Get.theme.primaryColorDark,
        unselectedColor: AppTheme.colors.disableBtn,
        children: {
          'PUBLIC': Text(
            'Public'.tr,
            style: TextStyle(
              fontFamily: 'Montserrat',
              color: Get.isDarkMode
                  ? Get.theme.primaryColorDark
                  : Get.theme.primaryColorLight,
              fontSize: 15.0,
              letterSpacing: 1.0,
            ),
          ),
          'PRIVATE': Text(
            'Private'.tr,
            style: TextStyle(
              fontFamily: 'Montserrat',
              color: Colors.black,
              fontSize: 15.0,
              letterSpacing: 1.0,
            ),
          )
        },
      ));

      formWidget.add(ReactiveTextField(
        formControlName: 'school.name',
        style: TextStyle(
            fontSize: 15.0,
            fontFamily: 'Montserrat',
            color: Get.isDarkMode ? Colors.white : Colors.black),
        textInputAction: TextInputAction.next,
        decoration: InputDecoration(
          alignLabelWithHint: true,
          labelText: 'School Name'.tr,
          labelStyle: TextStyle(
              fontFamily: 'Montserrat',
              color:
                  Get.isDarkMode ? Get.theme.primaryColorLight : Colors.black),
        ),
      ));
      formWidget.add(ReactiveTextField(
        formControlName: 'school.district',
        style: TextStyle(
            fontSize: 15.0,
            fontFamily: 'Montserrat',
            color: Get.isDarkMode ? Colors.white : Colors.black),
        textInputAction: TextInputAction.next,
        decoration: InputDecoration(
          alignLabelWithHint: true,
          labelText: 'School District'.tr,
          labelStyle: TextStyle(
              fontFamily: 'Montserrat',
              color:
                  Get.isDarkMode ? Get.theme.primaryColorLight : Colors.black),
        ),
      ));
      formWidget.add(
          ReactiveDropdownSearchMultiSelection<DropdownModel, DropdownModel>(
        dropdownDecoratorProps: DropDownDecoratorProps(
          dropdownSearchDecoration: InputDecoration(
            hintText: "Select Program".tr,
            labelText: "Program Type".tr,
            labelStyle: TextStyle(
                fontSize: 15.0,
                fontFamily: 'Montserrat',
                color: Get.isDarkMode
                    ? Get.theme.primaryColorLight
                    : Colors.black),
          ),
        ),
        // decoration: const InputDecoration(
        //   hintText: "Select Program",
        //   labelText: "Program Type",
        //   helperText: '',
        // ),
        //popupBackgroundColor: Colors.white,
        popupProps: PopupPropsMultiSelection.menu(
          showSelectedItems: true,
          //showSearchBox: true
        ),
        formControlName: 'school.programs',
        //mode: Mode.DIALOG,
        //showSelectedItems: true,
        items: allProgramTypes,
        //label: "Program Type",
        showClearButton: true,
        //showSearchBox: true,
        //maxHeight: 450,
        compareFn: (item, selectedItem) =>
            programTypeDropdownModelCompareFn(item, selectedItem),
      ));
      formWidget.add(ReactiveTextField(
        formControlName: 'contact.email',
        style: TextStyle(
            fontSize: 15.0,
            fontFamily: 'Montserrat',
            color: Get.isDarkMode ? Colors.white : Colors.black),
        // validationMessages: (control) => {
        //   'unique': 'The email is already used'.tr,
        // },
        validationMessages: {
          'unique': (_) => 'The email is already used'.tr,
        },
        textInputAction: TextInputAction.next,
        decoration: InputDecoration(
          alignLabelWithHint: true,
          labelText: 'Email'.tr,
          labelStyle: TextStyle(
              fontFamily: 'Montserrat',
              color:
                  Get.isDarkMode ? Get.theme.primaryColorLight : Colors.black),
        ),
      ));
      formWidget.add(ReactiveTextField(
        formControlName: 'contact.phone',
        style: TextStyle(
            fontSize: 15.0,
            fontFamily: 'Montserrat',
            color: Get.isDarkMode ? Colors.white : Colors.black),
        textInputAction: TextInputAction.next,
        decoration: InputDecoration(
          alignLabelWithHint: true,
          labelText: 'Phone'.tr,
          labelStyle: TextStyle(
              fontFamily: 'Montserrat',
              color:
                  Get.isDarkMode ? Get.theme.primaryColorLight : Colors.black),
        ),
      ));
      formWidget.add(ReactiveTextField(
        formControlName: 'address.street',
        style: TextStyle(
            fontSize: 15.0,
            fontFamily: 'Montserrat',
            color: Get.isDarkMode ? Colors.white : Colors.black),
        textInputAction: TextInputAction.next,
        decoration: InputDecoration(
          alignLabelWithHint: true,
          labelText: 'Address'.tr,
          labelStyle: TextStyle(
              fontFamily: 'Montserrat',
              color:
                  Get.isDarkMode ? Get.theme.primaryColorLight : Colors.black),
        ),
      ));
      formWidget.add(ReactiveTextField(
        formControlName: 'address.city',
        style: TextStyle(
            fontSize: 15.0,
            fontFamily: 'Montserrat',
            color: Get.isDarkMode ? Colors.white : Colors.black),
        textInputAction: TextInputAction.next,
        decoration: InputDecoration(
          alignLabelWithHint: true,
          labelText: 'City'.tr,
          labelStyle: TextStyle(
              fontFamily: 'Montserrat',
              color:
                  Get.isDarkMode ? Get.theme.primaryColorLight : Colors.black),
        ),
      ));
      formWidget.add(ReactiveTextField(
        formControlName: 'address.zipcode',
        style: TextStyle(
            fontFamily: 'Montserrat',
            fontSize: 15.0,
            color: Get.isDarkMode ? Colors.white : Colors.black),
        textInputAction: TextInputAction.next,
        decoration: InputDecoration(
          alignLabelWithHint: true,
          labelText: 'Zip Code'.tr,
          labelStyle: TextStyle(
              fontFamily: 'Montserrat',
              color:
                  Get.isDarkMode ? Get.theme.primaryColorLight : Colors.black),
        ),
      ));
      formWidget.add(SizedBox(
        height: 24,
      ));
      formWidget.add(CSCPicker(
        currentCountry: formCurrentCountry,
        currentState: formCurrentState,

        ///Enable disable state dropdown [OPTIONAL PARAMETER]
        showStates: true,

        /// Enable disable city drop down [OPTIONAL PARAMETER]
        showCities: false,

        ///Enable (get flag with country name) / Disable (Disable flag) / ShowInDropdownOnly (display flag in dropdown only) [OPTIONAL PARAMETER]
        flagState: CountryFlag.DISABLE,

        ///Dropdown box decoration to style your dropdown selector [OPTIONAL PARAMETER] (USE with disabledDropdownDecoration)
        dropdownDecoration: BoxDecoration(
            borderRadius: BorderRadius.all(Radius.circular(3.0)),
            color: Get.isDarkMode ? Get.theme.primaryColor : Colors.transparent,
            border: Border.all(
                color:
                    Get.isDarkMode ? Colors.transparent : Colors.grey.shade300,
                width: 1)),

        ///Disabled Dropdown box decoration to style your dropdown selector [OPTIONAL PARAMETER]  (USE with disabled dropdownDecoration)
        disabledDropdownDecoration: BoxDecoration(
            borderRadius: BorderRadius.all(
              Radius.circular(3.0),
            ),
            color: Colors.white,
            border: Border.all(
                color: Get.isDarkMode ? Colors.transparent : Colors.white,
                width: 1)),

        ///placeholders for dropdown search field
        countrySearchPlaceholder: "Country/Region",
        stateSearchPlaceholder: "State",
        citySearchPlaceholder: "City",

        ///labels for dropdown
        countryDropdownLabel: "Country/Region".tr,
        stateDropdownLabel: "State".tr,
        cityDropdownLabel: "City".tr,

        ///Default Country
        // defaultCountry: DefaultCountry.United_States,

        ///Disable country dropdown (Note: use it with default country)
        disableCountry: false,

        ///selected item style [OPTIONAL PARAMETER]
        selectedItemStyle: TextStyle(
          color: Colors.black,
          fontSize: 15,
        ),

        ///DropdownDialog Heading style [OPTIONAL PARAMETER]
        dropdownHeadingStyle: TextStyle(
            color: Get.isDarkMode ? Get.theme.primaryColorDark : Colors.black,
            fontSize: 18,
            fontWeight: FontWeight.bold),

        ///DropdownDialog Item style [OPTIONAL PARAMETER]
        dropdownItemStyle: TextStyle(
          color: Get.isDarkMode ? Get.theme.primaryColorDark : Colors.black,
          fontSize: 15,
        ),

        ///Dialog box radius [OPTIONAL PARAMETER]
        dropdownDialogRadius: 6.0,

        ///Search bar radius [OPTIONAL PARAMETER]
        searchBarRadius: 6.0,

        ///triggers once country selected in dropdown
        onCountryChanged: (value) {
          // setState(() {
          //   ///store value in country variable
          //   countryValue = value;
          // });
        },

        ///triggers once state selected in dropdown
        onStateChanged: (value) {
          // setState(() {
          //   ///store value in state variable
          //   stateValue = value;
          // });
        },

        ///triggers once city selected in dropdown
        onCityChanged: (value) {
          // setState(() {
          //   ///store value in city variable
          //   cityValue = value;
          // });
        },
      ));
      // formWidget.add(ReactiveDropdownSearch(
      //   formControlName: 'address.country',
      //   decoration: const InputDecoration(
      //     helperText: '',
      //     contentPadding: EdgeInsets.fromLTRB(12, 12, 0, 0),
      //     border: OutlineInputBorder(),
      //   ),
      //   mode: Mode.MENU,
      //   hint: 'Select a country',
      //   showSelectedItems: true,
      //   items: ['Brazil', 'Italia (Disabled)', 'Tunisia', 'Canada'],
      //   label: 'Country',
      //   showClearButton: true,
      //   showSearchBox: true,
      //   // popupItemDisabled: (String s) => s.startsWith('I'),
      // ));
      // formWidget.add(SizedBox(
      //   height: 24,
      // ));
      formWidget.add(SizedBox(
        height: 12,
      ));
      // formWidget.add(ReactiveDropdownSearch(
      //   formControlName: 'school.timezone',
      //   dropdownDecoratorProps: DropDownDecoratorProps(
      //     dropdownSearchDecoration: InputDecoration(
      //       hintText: "Select a time zone",
      //       labelText: "",
      //       contentPadding: EdgeInsets.fromLTRB(12, 12, 0, 0),
      //       border: OutlineInputBorder(),
      //     ),
      //   ),

      //   // decoration: const InputDecoration(
      //   //   hintText: 'Select a time zone',
      //   //   helperText: '',
      //   //   contentPadding: EdgeInsets.fromLTRB(12, 12, 0, 0),
      //   //   border: OutlineInputBorder(),
      //   // ),
      //   popupProps: PopupPropsMultiSelection.menu(
      //     showSelectedItems: true,
      //     //showSearchBox: true
      //   ),
      //   //mode: Mode.DIALOG,
      //   //hint: 'Select a time zone',
      //   //showSelectedItems: true,
      //   items: Constants.timeZones,
      //   //label: 'Time Zone',
      //   showClearButton: true,
      //   // //showSearchBox: true,
      //   // maxHeight: 450,
      //   //// popupItemDisabled: (String s) => s.startsWith('I'),
      // ));
      // formWidget.add(SizedBox(
      //   height: 12,
      // ));
      formWidget.add(Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Container(
            margin: EdgeInsets.only(bottom: 6.0),
            child: Text('Leader Board'.tr,
                style: TextStyle(
                  color: Colors.white,
                  fontFamily: 'Montserrat',
                  fontSize: 18.0,
                )),
          )
        ],
      ));
      final isSmallScreen =
          MediaQuery.of(context).size.width < Constants.DefinedScreenSmallSize;
      formWidget.add(
        isSmallScreen
            ? Column(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  Container(
                    width: double.infinity,
                    margin: EdgeInsets.only(
                      bottom: 6.0,
                    ),
                    padding: EdgeInsets.symmetric(horizontal: 12.0),
                    decoration: BoxDecoration(
                      color: Get.isDarkMode
                          ? Colors.black
                          : Colors.white.withOpacity(0.3),
                      borderRadius: BorderRadius.circular(3.0),
                    ),
                    child: Row(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          ReactiveCheckbox(
                              formControlName: 'leaderboard.disableclass'),
                          Text(
                            'Disable Class Leader Board'.tr,
                            style: TextStyle(
                                fontFamily: 'Montserrat',
                                color: Get.isDarkMode
                                    ? Get.theme.primaryColorDark
                                    : Colors.black),
                          ),
                        ]),
                  ),
                  Container(
                    width: double.infinity,
                    padding: EdgeInsets.symmetric(horizontal: 12.0),
                    decoration: BoxDecoration(
                      color: Get.isDarkMode
                          ? Colors.black
                          : Colors.white.withOpacity(0.3),
                      borderRadius: BorderRadius.circular(3.0),
                    ),
                    child: Row(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          ReactiveCheckbox(
                              formControlName: 'leaderboard.disableworld'),
                          Text(
                            'Disable World Class Leader Board'.tr,
                            style: TextStyle(
                                fontFamily: 'Montserrat',
                                color: Get.isDarkMode
                                    ? Get.theme.primaryColorDark
                                    : Colors.black),
                          ),
                        ]),
                  ),
                  Container(
                    width: double.infinity,
                    padding: EdgeInsets.symmetric(horizontal: 12.0),
                    decoration: BoxDecoration(
                      color: Get.isDarkMode
                          ? Colors.black
                          : Colors.white.withOpacity(0.3),
                      borderRadius: BorderRadius.circular(3.0),
                    ),
                    child: Row(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          ReactiveCheckbox(
                              formControlName:
                                  'leaderboard.disableDirectLogin'),
                          Text(
                            'Disable Direct Login'.tr,
                            style: TextStyle(
                                fontFamily: 'Montserrat',
                                color: Get.isDarkMode
                                    ? Get.theme.primaryColorDark
                                    : Colors.black),
                          ),
                        ]),
                  )
                ],
              )
            : Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  Container(
                    margin: EdgeInsets.only(
                      right: 6.0,
                    ),
                    padding: EdgeInsets.symmetric(horizontal: 12.0),
                    decoration: BoxDecoration(
                      color: Get.isDarkMode
                          ? Colors.black
                          : Colors.white.withOpacity(0.3),
                      borderRadius: BorderRadius.circular(3.0),
                    ),
                    child: Row(children: [
                      ReactiveCheckbox(
                          formControlName: 'leaderboard.disableclass'),
                      Text(
                        'Disable Class Leader Board'.tr,
                        style: TextStyle(
                            fontFamily: 'Montserrat',
                            color: Get.isDarkMode
                                ? Get.theme.primaryColorDark
                                : Colors.black),
                      ),
                    ]),
                  ),
                  Container(
                    padding: EdgeInsets.symmetric(horizontal: 12.0),
                    decoration: BoxDecoration(
                      color: Get.isDarkMode
                          ? Colors.black
                          : Colors.white.withOpacity(0.3),
                      borderRadius: BorderRadius.circular(3.0),
                    ),
                    child: Row(children: [
                      ReactiveCheckbox(
                          formControlName: 'leaderboard.disableworld'),
                      Text(
                        'Disable World Class Leader Board'.tr,
                        style: TextStyle(
                            fontFamily: 'Montserrat',
                            color: Get.isDarkMode
                                ? Get.theme.primaryColorDark
                                : Colors.black),
                      ),
                    ]),
                  ),
                  Container(
                    padding: EdgeInsets.symmetric(horizontal: 12.0),
                    decoration: BoxDecoration(
                      color: Get.isDarkMode
                          ? Colors.black
                          : Colors.white.withOpacity(0.3),
                      borderRadius: BorderRadius.circular(3.0),
                    ),
                    child: Row(children: [
                      ReactiveCheckbox(
                          formControlName: 'leaderboard.disableDirectLogin'),
                      Text(
                        'Disable Direct Login'.tr,
                        style: TextStyle(
                            fontFamily: 'Montserrat',
                            color: Get.isDarkMode
                                ? Get.theme.primaryColorDark
                                : Colors.black),
                      ),
                    ]),
                  )
                ],
              ),
      );
      formWidget.add(SizedBox(
        height: 12,
      ));
      formWidget.add(Container(
        margin: EdgeInsets.only(right: 30.0),
        child: isSmallScreen
            ? Padding(
                padding: const EdgeInsets.only(bottom: 30.0),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    ElevatedButton(
                        style: ElevatedButton.styleFrom(
                          fixedSize: Size.fromWidth(180),
                        ),
                        child: Text(
                          'Change Password'.tr,
                          style: TextStyle(
                              fontFamily: 'Montserrat', fontSize: 14.0),
                        ),
                        onPressed: () {
                          showGeneralDialog(
                              context: Get.context!,
                              transitionDuration: Duration(milliseconds: 400),
                              pageBuilder: (bc, ania, anis) {
                                return ChangeUserPasswordReactiveDialog(
                                    isTeacherOrSchooladmin: true);
                              });
                          // Get.to(() => ChangeUserPasswordReactiveDialog(
                          //     isTeacherOrSchooladmin: true));
                        }),
                    ReactiveFormConsumer(
                      builder: (context, form, child) {
                        return ElevatedButton(
                            style: ElevatedButton.styleFrom(
                              fixedSize: Size.fromWidth(180),
                            ),
                            child: Text(
                              'Submit'.tr,
                              style: TextStyle(
                                  fontFamily: 'Montserrat', fontSize: 14.0),
                            ),
                            onPressed: _onUpdate);
                      },
                    ),
                  ],
                ),
              )
            : Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  ElevatedButton(
                      child: Text(
                        'Change Password'.tr,
                        style:
                            TextStyle(fontFamily: 'Montserrat', fontSize: 14.0),
                      ),
                      onPressed: () {
                        showGeneralDialog(
                            context: Get.context!,
                            transitionDuration: Duration(milliseconds: 400),
                            pageBuilder: (bc, ania, anis) {
                              return ChangeUserPasswordReactiveDialog(
                                  isTeacherOrSchooladmin: true);
                            });
                        // Get.to(() => ChangeUserPasswordReactiveDialog(
                        //     isTeacherOrSchooladmin: true));
                      }),
                  SizedBox(
                    width: 9.0,
                  ),
                  ReactiveFormConsumer(
                    builder: (context, form, child) {
                      return ElevatedButton(
                          child: Text(
                            'Submit'.tr,
                            style: TextStyle(
                                fontFamily: 'Montserrat', fontSize: 14.0),
                          ),
                          onPressed: _onUpdate);
                    },
                  ),
                ],
              ),
      ));
      return formWidget;
    }

    _buildObxForm() {
      return Obx(() {
        // if (controller.classDetailsNew.value.classId == null) {}
        SchoolAdminProfile schoolAdminProfile =
            schoolAdminController.schoolAdminProfile.value;
        if (schoolAdminProfile.userName == null ||
            schoolAdminProfile.school == null) return Text('loading');
        SchoolAdminProfileDto? school = schoolAdminProfile.school;
        SchoolSettings? schoolSettings = schoolAdminProfile.schoolSettings;
        Log.debug('school name=' + (school?.schoolName).toString());
        form.control('school.type').value = school?.schoolType;
        form.control('school.district').value = school?.district;
        // form.control('school.district');
        form.control('school.name').value = school?.schoolName;
        form.control('school.programs').value = school?.programType
            ?.map((e) => DropdownModel(e.programName, e.displayName))
            .toList();
        form.control('contact.email').value = school?.schoolEmail;
        form.control('contact.phone').value = school?.phone;
        form.control('address.street').value = school?.address;
        form.control('address.city').value = school?.city;
        form.control('address.zipcode').value = school?.zipCode;
        formCurrentCountry = school?.country;
        formCurrentState = school?.state;
        Log.debug('timeZone=${schoolAdminProfile.timeZone}');
        form.control('school.timezone').value = schoolAdminProfile.timeZone;
        form.control('leaderboard.disableclass').value =
            schoolSettings?.disableClassLeaderboards ?? false;
        Log.debug(
            'leaderboard.disableclass=${form.control('leaderboard.disableclass').value}');
        form.control('leaderboard.disableworld').value =
            schoolSettings?.disableWorldLeaderboard ?? false;
        form.control('leaderboard.disableDirectLogin').value =
            school?.disableDirectLogin ?? false;
        Log.debug(
            'leaderboard.disableworld=${form.control('leaderboard.disableworld').value}');

        // List<DropdownModel> selectedClassIds = [];

        // teacherItemModel.classId?.forEach((classId) {
        //   Log.debug("forEach classId=$classId");
        //   var find = controller.classItemsWithoutAll
        //       .where((element) => element.classId == classId);
        //   if (find.isNotEmpty)
        //     selectedClassIds
        //         .add(DropdownModel(find.first.classId, find.first.className));
        // });
        // Log.debug("selectedClassIds=$selectedClassIds");
        // form.control('classIds').value = selectedClassIds;
        return ReactiveForm(
            formGroup: form, child: Column(children: _buildForm()));
      });
    }

    final PageStyles _pageStyles = PageStyles();
    // final isSmallScreen =
    //     MediaQuery.of(context).size.width < Constants.DefinedScreenSmallSize;
    return Scaffold(
        backgroundColor: Colors.transparent,
        body: SingleChildScrollView(
          primary: false,
          child: Container(
            decoration: BoxDecoration(
              color: Get.isDarkMode
                  ? AppTheme.colors.darkTheme2
                  : Colors.white.withOpacity(0.3),
              borderRadius: BorderRadius.circular(6.0),
            ),
            padding: _pageStyles.pageEdgeInsets(),
            child: _buildObxForm(),
          ),
        ));
  }
}
